﻿namespace Snipps.Core
{
    using System;
    using System.Collections.Generic;

    using Snipps.Core.Entities;

    public static class SampleData
    {
        private static readonly string[] _programingLangsNames = new[]
                                                                           {
                                                                               "Assembler", "C#", "C++", "ObjectiveC", "CSS", "Delphi", "F#"
                                                                               , "HTML", "Java", "JavaScript", "Perl", "PHP", 
                                                                               "Python", "Ruby", "Scala", "SQL", "Text", "VB", 
                                                                               "VBScript", "XAML", "XML","XSLT"
                                                                           };

        public static IList<Tag> GenerateFakeTags()
        {
            var tags = new List<Tag>();

            for (var i = 1; i < 40; i++)
            {
                tags.Add(new Tag { Name = "tag" + i, Id = i });
            }

            return tags;
        }

        public static IList<Snippet> GenerateRandomSnippets()
        {
            var rand = new Random();
            var snippets = new List<Snippet>();
             
            var tags = GenerateFakeTags();
            var maxTagIndex = tags.Count - 1;
            var programmingLangs = GetAllProgrammingLangs();
            var maxProgrammingLangIndex = programmingLangs.Count - 1;

            for (var i = 1; i < 500; i++)
            {
                var randomName = LoremIpsumGenerator.GetWords(rand.Next(1, 7));
                var snippet = new Snippet { Name = randomName + i, Id = i };

                var tagsCountInSnippet = rand.Next(0, 10);
                for (var j = 0; j < tagsCountInSnippet; j++)
                {
                    var tagIndex = rand.Next(0, maxTagIndex);
                    var tag = tags[tagIndex];
                    if (!snippet.Tags.Contains(tag))
                    {
                        snippet.Tags.Add(tag);
                    }
                }

                var programmingLangIndex = rand.Next(0, maxProgrammingLangIndex);
                snippet.ProgrammingLang = programmingLangs[programmingLangIndex];

                snippet.Content = LoremIpsumGenerator.GetWords(rand.Next(60, 200));
                snippets.Add(snippet);
            }

            return snippets;
        }

        public static IList<ProgrammingLang> GetAllProgrammingLangs()
        {
            var programmingLangs = new List<ProgrammingLang>();

            for (var i = 0; i < _programingLangsNames.Length; i++)
            {
                var slangName = _programingLangsNames[i];
                var slang = new ProgrammingLang { Name = slangName, Id = i + 1 };
                programmingLangs.Add(slang);
            }

            return programmingLangs;
        }
    }
}